package com.gpStudy.design.proxy.JDKDynamicProxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class DynamicUserProxy implements InvocationHandler {

    private Object obj;

    public DynamicUserProxy(Object obj) {
        this.obj = obj;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        this.before();
        try {
            return method.invoke(obj,args);
        } finally {
            this.after();
        }

    }

    public void before(){
        System.out.println("DynamicUserProxy 前置方法");
    }

    public void after(){
        System.out.println("DynamicUserProxy 后置方法");
    }
}
